package com.deng.template.dao.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.deng.template.dao.model.UserDO;
import com.deng.template.dao.model.query.UserQuery;
import org.apache.commons.lang3.StringUtils;

import java.util.List;
import java.util.Objects;

/**
 * @author Deng
 * @describe
 * @date 2022/11/9
 */
public interface UserMapper extends BaseMapper<UserDO> {

   default List<UserDO> queryLisByCondition(UserQuery query) {
        QueryWrapper<UserDO> wrapper = new QueryWrapper<>();
        wrapper.lambda()
                .eq(Objects.nonNull(query.getId()), UserDO::getId, query.getId())
                .eq(StringUtils.isNotBlank(query.getMail()), UserDO::getMail, query.getMail())
                .ge(Objects.nonNull(query.getStartCreateTime()), UserDO::getGmtCreate, query.getStartCreateTime())
                .le(Objects.nonNull(query.getEndCreateTime()), UserDO::getGmtCreate, query.getEndCreateTime())
                .ge(Objects.nonNull(query.getStartBirthday()), UserDO::getBirthday, query.getStartBirthday())
                .le(Objects.nonNull(query.getEndBirthday()), UserDO::getBirthday, query.getEndBirthday());
        return selectList(wrapper);
    }

}
